package com.example.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.bean.Banner;
import com.example.fruit.R;
import com.lidroid.xutils.BitmapUtils;

import java.util.List;


public class BannerAdapter extends AppBaseAdapter<Banner> {
    private BitmapUtils bitmapUtils;

    public BannerAdapter(Context context, List<Banner> list, BitmapUtils bitmapUtils) {
        super(context, list);
        this.bitmapUtils = bitmapUtils;
    }

    @Override
    public View getItemView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.item_banner, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        bitmapUtils.display(holder.img, list.get(position).getPhoto());
        return view;
    }

    private static class ViewHolder {
        ImageView img;
        public ViewHolder(View itemView) {
            this.img = (ImageView) itemView.findViewById(R.id.img_itemId);
        }
    }


}
